package com.yjhb.android.sbz.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.yjhb.android.sbz.R;
import com.yjhb.android.sbz.entity.NewcomerItem;
import com.jojo.android.zxlib.base.BaseRecyclerAdapter;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 创建者 zx
 * 创建时间 2020/12/28 17:37
 */
public class NewcomerWelfareAdapter extends BaseRecyclerAdapter<NewcomerWelfareAdapter.NewcomerWelfareHolder, NewcomerItem> {
    private final String TAG = "NewcomerWelfareAdapter";

    boolean downtimeEnd;

    public NewcomerWelfareAdapter(Context context) {
        super(context);
    }

    @Override
    protected NewcomerWelfareHolder getHolder(View v) {
        return new NewcomerWelfareHolder(v);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.item_newcomer;
    }

    public void setDowntimeEnd(boolean downtimeEnd) {
        this.downtimeEnd = downtimeEnd;
    }

    public boolean isDowntimeEnd() {
        return downtimeEnd;
    }

    @Override
    public void onBindViewHolder(@NonNull NewcomerWelfareHolder holder, int position) {
        holder.numTv.setText("" + entity.getNumber());
        holder.titleTv.setText(entity.getTitle());
        holder.contentTv.setText(entity.getContent());
        holder.money_tv.setText("+" + entity.getMoney() + "元");

        switch (entity.getState()) {
            case 0:
                if (downtimeEnd){
                    holder.getRedPack.setTextColor(context.getResources().getColor(R.color.gray_66));
                    holder.getRedPack.setText("已过期");
                    holder.getRedPack.setEnabled(false);
                }else {
                    holder.getRedPack.setTextColor(Color.WHITE);
                    holder.getRedPack.setText("去完成");
                    holder.getRedPack.setEnabled(true);
                }
                break;
            case 1:
                holder.getRedPack.setTextColor(context.getResources().getColor(R.color.gray_66));
                holder.getRedPack.setText("已领取");
                holder.getRedPack.setEnabled(false);
                break;
            case 2:
                if (downtimeEnd){
                    holder.getRedPack.setTextColor(context.getResources().getColor(R.color.gray_66));
                    holder.getRedPack.setText("已过期");
                    holder.getRedPack.setEnabled(false);
                }else {
                    holder.getRedPack.setTextColor(Color.WHITE);
                    holder.getRedPack.setText("领红包");
                    holder.getRedPack.setEnabled(true);
                }
                break;
        }
        final int index = position;
        NewcomerItem entity = data.get(position);
        holder.getRedPack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (itemClickListener != null) {
                    itemClickListener.onViewClick(v, "领红包", index, entity);
                }
            }
        });
    }

    class NewcomerWelfareHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.num_tv)
        TextView numTv;
        @BindView(R.id.title_tv)
        TextView titleTv;
        @BindView(R.id.content_tv)
        TextView contentTv;
        @BindView(R.id.get_red_pack)
        TextView getRedPack;
        @BindView(R.id.money_tv)
        TextView money_tv;

        public NewcomerWelfareHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}
